<?php include "./pc/view/header.inc.htm"; ?>
<div class="container">
    <div class="page-canvas">
        <div class="signin">
            <h1>注册用户</h1>
            <form method="POST" id="create_form" action="user-create.htm">
            <input type="hidden" name="referer" value="<?php echo $referer; ?>">
                <fieldset>
                    <div class="field">
                        <input class="form-control" type="text" placeholder="邮箱" name="email" maxlength="36">
                    </div>
                    <?php if($conf['user_create_email_on']) { ?>
                    <div class="field">
                        <input type="text" placeholder="验证码" name="verifycode"> 
                    </div>
                    <div class="field">
                        <button class="Button Button--primary" id="sendactive" type="button" loading-text="正在发送...">获取邮件验证码</button> 
                    </div>
                    <?php } ?>
                </fieldset>
                <div class="button">
                    <button class="Button Button--primary" type="submit" loading-text="正在提交...">下一步</button>
                    <a class="forgot" href="user-login.htm">登录</a>
                </div>
            </form>
        </div>
        <div class="info">
            <p>
                您可以直接使用第三方帐号登录
                <span class="point">·</span>
                <a href="http://flarum.cc/plugin/xn_qq_login/qq_login.php?action=login">QQ登录 »</a>
                <!-- <span class="point">·</span>
                <a href="#">微信登录 »</a> -->
            </p>
        </div>
    </div>
</div>

<?php include "./pc/view/footer.inc.htm"; ?>

<script>

var jform = $('#create_form');
var jemail = jform.find('input[name="email"]').focus();
var jverifycode = jform.find('input[name="verifycode"]');
var jsubmit = jform.find('button[type="submit"]');

$.pdata('referer', '<?php echo $referer; ?>');

jform.off('submit').on('submit', function() {
    jsubmit.button('loading');
    var postdata = jform.serialize();
    $.xpost(jform.attr('action'), postdata, function(code, message) {
        if(code == 0) {
            window.location = 'user-setpw.htm';
            return;
        } else if(code == 1) {
            jemail.popover(message).focus();
        } else if(code == 2) {
            jverifycode.popover(message).focus();
        } else {
            alert(message);
        }
        jsubmit.button('reset');
    });
    return false;
});

var jsendactive = $('#sendactive');
jsendactive.on('click', function() {
    if(!jemail.val()) {
        jemail.popover('请输入 Email').focus();
        return false;
    }
    jsendactive.button('loading');
    $.xpost('user-sendactive.htm', {email: jemail.val()}, function(code, message) {
        if(code == 0) {
            button_count_down(jsendactive, '发送成功 ({time})', 30);
            return;
        } else if(code == 1) {
            jemail.popover(message).focus();
        } else {
            alert(message);
        }
        jsendactive.button('reset');
    });
});

// 倒计时
function button_count_down(jbutton, text, seconds) {
    jbutton.button('disabled');
    if(window.button_count_down_t) clearInterval(window.button_count_down_t);
    window.button_count_down_t = setInterval(function() {
        if(seconds-- <= 0) {
            clearInterval(window.button_count_down_t);
            window.button_count_down_t = 0;
            jbutton.button('reset');
            return;
        }
        text2 = text.replace('{time}', seconds);
        jbutton.button(text2);
    }, 1000);
}

</script>